package com.synchrona.pluginManager;

import java.util.ArrayList;
import java.util.List;

import com.synchrona.account.Account;
import com.synchrona.common.EnumService;
import com.synchrona.syncDataAccess.*;
import com.synchrona.update.Update;
import com.synchrona.user.User;

public class PluginManager {

	public PluginManager() {

	}

	public void synchronizeStatus(Update update) {
		try {
			System.out.println("Synchronizing data......");
			List<Account> accountList = (List<Account>) update.getUser().getAccountList();
			for (Account account : accountList) {
				String serviceId = account.getServiceId();
				if (serviceId.equals("1")) {
					TwitterPlugin twitterPlugin = new TwitterPlugin();
					System.out.println("Service: Twitter");
					twitterPlugin.updateStatus(update.getData(), account);
				}
				if (serviceId.equals("2")) {
					FacebookPlugin fbPlugin = new FacebookPlugin();
					System.out.println("Service: Facebook");
					fbPlugin.runFB(update.getData(), account);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void getComments(User user){
		try {
			System.out.println("Recieving Comments...");
			List<Account> accountList = (List<Account>) user.getAccountList();
			if((accountList != null)&&(accountList.size() != 0)){
				for (Account account : accountList) {
				String serviceId = account.getServiceId();
				System.out.println(serviceId);
					if (serviceId.equals("1")) {
						TwitterPlugin plugin = new TwitterPlugin();
						System.out.println("Service: Twitter");
						plugin.getTweets(account);
					}
					if(serviceId.equals("3")){
						Blogger blogger = new Blogger();
						System.out.println("Service: Blogger");
						blogger.getLastBlogComments(account);
					}
				}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
